package com.moon.interview.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.qcloud.cos.utils.StringUtils;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
@TableName("question")
public class Question extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /** id */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    /** 标题 */
    @TableField("title")
    private String title;

    /** 内容 */
    @TableField("content")
    private String content;

    /** 标签 */
    @TableField("tags")
    private String tags;

    /** 推荐答案 */
    @TableField("answer")
    private String answer;

    /** 用户Id */
    @TableField("user_id")
    private Long userId;

    /**
     * 标签转换  list转换成str
     * @param tagList
     * @return
     */
    public String transTagStr(List<String> tagList) {
       return tagList == null || tagList.size() == 0 ? "" : StringUtils.join(tagList);
    }

    /**
     * 标签转换  str转换成list
     * @param tagStr
     * @return
     */
    public List<String> transTagList(String tagStr) {
        return StringUtils.isNullOrEmpty(tagStr) ? null : List.of(tagStr.split(","));
    }

}
